package com.prolestar.participation.service.impl;

import java.util.List;

import com.prolestar.common.core.domain.AjaxResult;
import com.prolestar.participation.domain.ParticipationStatus;
import com.prolestar.participation.domain.PsParticipation;
import com.prolestar.participation.domain.SelectUrl;
import com.prolestar.participation.mapper.PsParticipationMapper;
import com.prolestar.participation.service.IPsParticipationService;
import com.prolestar.system.domain.SysConfig;
import com.prolestar.system.service.ISysConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 公众参与Service业务层处理
 *
 * @author xuyp
 * @date 2022-11-21
 */
@Service
public class PsParticipationServiceImpl implements IPsParticipationService
{
    @Autowired
    private PsParticipationMapper psParticipationMapper;

    @Autowired
    private ISysConfigService sysConfigService;

    /**
     * 查询公众参与
     *
     * @param id 公众参与主键
     * @return 公众参与
     */
    @Override
    public PsParticipation selectPsParticipationById(Long id)
    {
        return psParticipationMapper.selectPsParticipationById(id);
    }

    /**
     * 查询公众参与列表
     *
     * @param psParticipation 公众参与
     * @return 公众参与
     */
    @Override
    public List<PsParticipation> selectPsParticipationList(PsParticipation psParticipation)
    {
        return psParticipationMapper.selectPsParticipationList(psParticipation);
    }

    /**
     * 新增公众参与
     *
     * @param psParticipation 公众参与
     * @return 结果
     */
    @Override
    public int insertPsParticipation(PsParticipation psParticipation)
    {
        psParticipation.setStatus(ParticipationStatus.PENDING);
        return psParticipationMapper.insertPsParticipation(psParticipation);
    }

    /**
     * 修改公众参与
     *
     * @param psParticipation 公众参与
     * @return 结果
     */
    @Override
    public int updatePsParticipation(PsParticipation psParticipation)
    {
        return psParticipationMapper.updatePsParticipation(psParticipation);
    }

    /**
     * 批量删除公众参与
     *
     * @param ids 需要删除的公众参与主键
     * @return 结果
     */
    @Override
    public int deletePsParticipationByIds(Long[] ids)
    {
        return psParticipationMapper.deletePsParticipationByIds(ids);
    }

    /**
     * 删除公众参与信息
     *
     * @param id 公众参与主键
     * @return 结果
     */
    @Override
    public int deletePsParticipationById(Long id)
    {
        return psParticipationMapper.deletePsParticipationById(id);
    }

    /**
     *  查询url
     * @return
     */
    @Override
    public SelectUrl selectUrl() {
        String config = sysConfigService.selectConfigByKey("system.url");
        SelectUrl selectUrl = new SelectUrl();
        selectUrl.setUrl(config+"/publicParticipation");
        return selectUrl;
    }

    /**
     * 不采纳
     * @param psParticipation
     * @return
     */
    @Override
    public AjaxResult accept(PsParticipation psParticipation) {
         psParticipation.setStatus(ParticipationStatus.BILURRRBE);
          psParticipationMapper.updatePsParticipation(psParticipation);
          return AjaxResult.success();
    }
}
